<?php
defined('IN_CMS') or die('Direct access to Script restricted.');

$city_id = 0;

// Получим код выбранного города из адресной строки
$city_code = self::$obj_request->getParam(1);
if ($city_code != '')
{
	$city_id = self::$obj_geo->getCityByCode($city_code);
}

//
if ($city_id > 0)
{
	// Покажем информацию о выбранном городе
	$city = self::$obj_geo->getCityByID($city_id);
	
	self::$obj_template->assign('CITY', $city);
	
	// Карта
	self::$obj_page->showControl(
		'map', 
		'main.tpl_page_content.city', 
		self::$cfg['controls']['map']['cache'], 
		array
		(
			'map_x' => $city['map_x'], 
			'map_y' => $city['map_y'], 
			'zoom' => $city['map_zoom']
		)
	);
	
	// 
	
	//
	self::$obj_template->parse('main.tpl_page_content.city');
}
else 
{
	// Покажем список городов
	$country_id = 376; // Israel
	$arr_zones = self::$obj_geo->getCountryZones($country_id); //array(86, 82, 84, 81, 83, 85, 80);
	
	for ($z = 0; $z < count($arr_zones); $z++)
	{
		$zone_id = $arr_zones[$z]['zone_id'];
		unset($cities, $arr_cities);
		$cities = self::$obj_geo->getCities($country_id, $zone_id);
		$size = ceil(count($cities)/4);
		$arr_cities = array_chunk($cities, $size);
		for ($i = 0; $i < count($arr_cities); $i++)
		{
			//
			if ($i == count($arr_cities) - 1)
			{
				self::$obj_template->assign('latest', 'latest');
			}
			else 
			{
				self::$obj_template->assign('latest', '');
			}
			//
			for ($j = 0; $j < count($arr_cities[$i]); $j++)
			{
				self::$obj_template->assign('DATA', $arr_cities[$i][$j]);
				self::$obj_template->parse('main.tpl_page_content.cities.arr_zones.arr_cities.items');
			}
			self::$obj_template->parse('main.tpl_page_content.cities.arr_zones.arr_cities');
		}
		self::$obj_template->assign('DATA', $arr_zones[$z]);
		self::$obj_template->parse('main.tpl_page_content.cities.arr_zones');
	}
	
	//
	self::$obj_page->showControl(
		'map', 
		'main.tpl_page_content.cities', 
		self::$cfg['controls']['map']['cache'], 
		array
		(
			'map_x' => 35.299,  // ^ - left
			'map_y' => 31.999,  // ^ - down
			'zoom' => 9 
		)
	);
	
	self::$obj_template->parse('main.tpl_page_content.cities');
}

?>